<?php
include_once("../includes/page_utf_class.php");
//=======================
if(!empty($_GET['deid']))
{
	$sql="delete from ".ORDER." where id='$_GET[deid]'";
	$db->query($sql);
}
if (!empty($_GET['username']))
{
    $sqlc="select userid from ".ALLUSER." where user='".$_GET['username']."'";
	$db->query($sqlc);
	$us=$db->fetchRow();
    if(!empty($_GET['ordertype'])&&$_GET['ordertype']=='b')
       $subsql.=" and buyer_id='".$us['userid']."'";
	elseif (!empty($_GET['ordertype'])&&$_GET['ordertype']=='s')
	   $subsql.=" and seller_id='".$us['userid']."'";
	else
       $subsql.=" and ( buyer_id='".$us['userid']."' or seller_id='".$us['userid']."')";
}

if (isset($_GET['orderstatus']))
{
	$subsql.=" and status='".$_GET['orderstatus']."'";
} 
$sql="select * from ".ORDER." where 1=1 $subsql  order by id desc";
//=============================
	$page = new Page;
	$page->listRows=20;
	if (!$page->__get('totalRows')){
		$db->query($sql);
		$page->totalRows = $db->num_rows();
	}
	$sql .= "  limit ".$page->firstRow.",20";
	$pages = $page->prompt();
//=====================
$db->query($sql);
$re=$db->getRows();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE><?php echo lang_show('orderm');?></TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<link href="main.css" rel="stylesheet" type="text/css" />
</HEAD>
<body>

<div class="bigbox">
	<div class="bigboxhead"><?php echo lang_show('oum');?></div>
	<div class="bigboxbody">
	<form method="get" action="" style="margin-top:0px;">
	   <table cellpadding="0" cellspacing="0" width="100%">
    <tr>
      <td class="searh_left">
	  <?php echo lang_show('ouname');?></td>
      <td> <input class="text" type="text" name="username" id="username" value="<?php echo $_GET['username'];?>" />
      </td>
    </tr>
    <tr>
      <td ><?php echo lang_show('ostatus');?></td>
      <td ><select class="select" name="orderstatus" id="orderstatus">
        <option value="" selected><?php echo lang_show('otypeall');?></option>
        <?php
		 include("../lang/$config[language]/company_type_config.php");
		 foreach($order_status as $key=>$v)
		 {
		 ?>
        <option value="<?php echo $key;?>" <?php if (isset($_GET['orderstatus'])&&$_GET['orderstatus']==$key) echo "selected";?>> <?php echo $v;?> </option>
        <?php } ?>
      </select></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input class="btn" type="submit" name="Submit" value="<?php echo lang_show('search');?>" />
        <input name="m" type="hidden" value="product" />
        <input name="s" type="hidden" value="user_order.php" /></td>
    </tr>
	   </table></form>
 	 <table width="100%" border="0" cellpadding="2" cellspacing="0">   
      <tr class="theader"> 
      <td width="7%" align="center"  ><?php echo lang_show('oid');?></td>
	  <td width="12%"  ><?php echo lang_show('ostatus');?></td>
      <td width="29%" ><?php echo lang_show('obuyer');?></td>
      <td width="11%" align="left" ><?php echo lang_show('otime');?></td>
      <td width="9%" align="center" ><?php echo lang_show('oaction');?></td>
      </tr>
    <?php
	      //----送货方式
		  $fg=array('pu'=>'平邮',
		            'kd'=>'快递',
					'ems'=>'EMS');
	      foreach ($re as $v)
          {  
			  $sqls="select a.user,b.company from ".ALLUSER." a, ".USER." b where a.userid=b.userid and b.userid='".$v['buyer_id']."'";
              $db->query($sqls);
		      $b=$db->fetchRow();
	?> 
         <tr> 
         <td width="7%" align="center" >
         
		 <a href="?m=product&s=order_detail.php&oid=<?php echo $v['id'];?>"><?php echo $v['id']; ?></a>
         
		 </td>
		 <td width="10%" ><?php echo $order_status[$v['status']]?>&nbsp;</td>
         <td width="44%">
         <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="20%" align="right">买家帐号:</td>
            <td width="30%" align="left"> <?php echo $b['user'];?></td>
            <td width="20%" align="right">收货人姓名:</td>
            <td width="30%" align="left"><?php echo $v['buyer_name']?></td>          
          </tr>
          <tr>
            <td  align="right">固定电话:</td>
            <td align="left"><?php echo $v['buyer_tel']?></td>
            <td align="right">手机:</td>
            <td align="left"><?php echo $v['buyer_mobile']?></td>
          </tr>
           <tr>
            <td align="right">订单总价:</td>
            <td align="left"><?php  echo number_format($v['product_price']+$v['logistics_price '],2)?>元(含运费)</td>
            <td align="right">送货方式:</td>
            <td align="left"><?php  echo $fg[$v['logistics_type']]?></td>
          </tr>
            <tr>
            <td align="right">收货人地址:</td>
            <td align="left"><?php echo $v['buyer_addr'];?></td>
            <td align="right">邮编:</td>
            <td align="left"><?php  echo $v['buyer_zip'];?></td>
          </tr>
        </table>
  
         </td>
         <td width="11%" align="left"><?php echo date("Y-m-d H:i",$v['creat_time']); ?></td>
         <td width="9%" align="center">
		 <a href="sendmail.php?userid=<?php echo $v['suid']; ?>"><?php echo $mailimg;?></a>
		 <a onClick="return confirm('确信删除吗？');" href="?m=product&s=user_order.php&deid=<?php echo $v['id'];?>"><?php echo $delimg;?></a>
		 </td>
      </tr>
    <?php 
        }
	?>
	<tr>
	<td colspan="6" align="right"><div class="page"><?php echo $pages?></div></td>
	</tr>
  </table>
  <div align="right"></div>
  </div>
</div>
</body>
</html>
